﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.Services.SheepMale.Api.Application.Command.MarketCommand;
using S.Services.SheepMale.Api.Extensions;
using System.Security.Claims;
using Yitter.IdGenerator;

namespace S.Services.SheepMale.Api.Controllers
{
    /// <summary>
    /// 个体销售管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName =nameof(ApiVersionInfo.个体销售))]
    public class EntityMarketController : ControllerBase
    {
        private readonly IMediator mediator;
        public EntityMarketController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 羊只销售添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> HandleAddMarket(MarketAddCommand request, CancellationToken cancellationToken)
        {
            request.CreateBy = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            return Ok(await mediator.Send(request));
        }
        /// <summary>
        /// 个体销售批删
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> HandleDelAllMarket([FromQuery]MarketDelAllCommand request, CancellationToken cancellationToken)
        {
            return Ok(await mediator.Send(request));
        }
        /// <summary>
        /// 个体销售单删
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> HandleDelMarket([FromQuery]MarketDelCommand request, CancellationToken cancellationToken)
        {
            return Ok(await mediator.Send(request));
        }
        /// <summary>
        /// 个体销售修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> HandleUpdMarket(MarketUpdCommand request, CancellationToken cancellationToken)
        {
			request.UpdateBy = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
			return Ok(await mediator.Send(request));
        }
        /// <summary>
        /// 个体销售审核
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPut]
		public async Task<IActionResult> HandleAllExamine([FromQuery] MarketAllExamineCommand request, CancellationToken cancellationToken)
		{
			return Ok(await mediator.Send(request));
		}
        /// <summary>
        /// 个体销售重新审核
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPut]
		public async Task<IActionResult> HandleAllReversal([FromQuery]MarketAllReversalCommand request, CancellationToken cancellationToken)
		{
            return Ok(await mediator.Send(request));
		}
	}
}
